<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/content/variable.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<%@ include file="/content/head.jsp"%>
</head>
<body>
    <div class="row">
        <div class="col-md-12">
            <div class="box box-info">
                <div class="box-header with-border">
                    <h3 class="box-title">修改私播</h3>
                </div>
              <form id="editInfo" class="form-horizontal" role="form" onsubmit="javascript:saveInfo();">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">名字：</label>
                            <div class="col-sm-8 ">
                                <input type="text" value="${obj.name}" id="name" class="form-control" name="name"
                                       placeholder="名字">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
							<label for="state" class="col-sm-1 control-label">类型：</label>
							  <div class="col-sm-8 ">
                             <select id="type" name="type" class="form-control select2">
                               	<option selected="selected" value="1">首页</option>
                                <option value="2">附近人</option>
                             </select>
                             </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="tryUrl" class="col-sm-2 control-label">视频地址：</label>
                             <div class="col-md-8">
								<input type="file" class="file-loading" id="tryUrlVideoFile" accept="video/*">
								<input type="text" value="${obj.tryUrl}" class="form-control input-sm" id="tryUrlVideoUrl" name="tryUrl"> 
							</div>
							<div class="col-sm-2">
								<span class="help-inline" style="color: #a94442"></span>
							</div>
                        </div>
                        
                        <br>
                        <div class="form-group">
                            <label for="imgUrl" class="col-sm-2 control-label">封面：</label>
                            <div class="col-md-8">
								<input type="file" class="file-loading" id="imgUrlImgFile" accept="image/*">
								<input type="text" value="${obj.imgUrl}" class="form-control input-sm" id="imgUrlImgUrl" name="imgUrl"> 
							</div>
							<div class="col-sm-2">
								<span class="help-inline" style="color: #a94442"></span>
							</div>
                        </div>
                        <br>
                        <input type="hidden" name ="videoId" id="videoId" value="${obj.videoId}"/>
                        <div class="col-md-offset-5 col-md-9">
                            <button type="submit" class="btn btn-success">确定</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
    <!-- /.row -->
<%@ include file="/content/js.jsp"%>
<script type="text/javascript">
var type = ${obj.type};
$(function(){
	//初始化下拉框默认值
	document.getElementById("type").value = type;
	//封面上传
	   $("#imgUrlImgFile").fileinput({
	   	uploadUrl:"<%=path%>/home/uploadClassifyImg",
	       browseClass: "btn btn-primary",
	       enctype: 'multipart/form-data',
	       autoReplace:true,
	       dropZoneEnabled:false,
	       browseLabel: "上传",
	       showCaption: false,
	       showRemove: false,
	       showUpload: true,
	       showZoom:false,
	       maxFileCount:1, ////表示允许同时上传的最大文件个数
	       allowedFileTypes:["image"], //文件的选择类型[‘image’, ‘html’, ‘text’, ‘video’, ‘audio’, ‘flash’, ‘object’]
	       previewSettings:{
	       	image: {width: "auto", height: "100px"},
	       },
	   });
	   $('#imgUrlImgFile').on('fileuploaded', function(event, data, previewId, index) {
	   	var path = data.response.initialPreviewConfig[0].extra.path;
	       $("#imgUrlImgUrl").val(path);
	   });
	   $('#imgUrlImgFile').on('filedeleted', function(event,key,jqXHR,data) {
	   	if($("#imgUrlImgUrl").val()==data.path)
	   		$("#imgUrlImgUrl").val('');
	   }); 
	 //视频上传
	   $("#tryUrlVideoFile").fileinput({
	   	uploadUrl:"<%=path%>/home/uploadClassifyVideo",
	       browseClass: "btn btn-primary",
	       autoReplace:true,
	       dropZoneEnabled:false,
	       browseLabel: "上传",
	       showPreview:false,
	       showCaption: false,
	       showRemove: false,
	       showUpload: true,
	       showZoom:false,
	       maxFileCount:1, ////表示允许同时上传的最大文件个数
// 	       allowedFileTypes:["video"], //文件的选择类型[‘image’, ‘html’, ‘text’, ‘video’, ‘audio’, ‘flash’, ‘object’]
	       maxFileSize:0,//单位为kb，如果为0表示不限制文件大小
	       previewSettings:{
	       		type:"video",
	    		video: {width: "auto", height: "100px"},
	      },
	   });
	   $('#tryUrlVideoFile').on('fileuploaded', function(event, data, previewId, index) {
	   	var path = data.response.initialPreviewConfig[0].extra.path;
	       $("#tryUrlVideoUrl").val(path);
	       $("#tryUrlVideoUrl").triggerHandler("blur");
	   });
	   $('#tryUrlVideoFile').on('filedeleted', function(event,key,jqXHR,data) {
	   	if($("#tryUrlVideoUrl").val()==data.path)
	   		$("#tryUrlVideoUrl").val('');
	   	$("#tryUrlVideoUrl").triggerHandler("blur");
	   }); 
	});

		function saveInfo(){
			var name = $("#name").val();
			var type = $("#type").val();
			var imgUrl = $("#imgUrlImgUrl").val();
			var tryUrl = $("#tryUrlVideoUrl").val();
			var videoId = $("#videoId").val();
			$.ajax({
				type:"post",
				async: false,
				url:"<%=path%>/home/alertHomeSave",
				data:{type:type,
					videoId:videoId,
					name:name,
					imgUrl:imgUrl,
					tryUrl:tryUrl},
				dataType:"json",
				success: function(data){
					if (data.missage == "success") {
	                    modalMsg("修改成功", "success");
	                    window.parent.location.reload();
	                    var index = parent.layer.getFrameIndex(window.name);
	                    parent.layer.close(index);
	                }else if(data.missage == "error"){
	                	 modalMsg("修改失败", "error");
	                }else{
	                	 modalMsg("更新失败", "error");
	                }
				}
			});
		}
</script>
</body>
</html>